package com.ggk911.pharmacy_system.util;

import lombok.Data;

import java.util.List;

/**
 * 包装类
 *
 * @author ggk-911
 * @version 1.0 2023/2/14 9:12
 */
@Data
public class RestResult<T> {
    //状态码
    private Integer code;
    //文字
    private String message;
    //集合
    private List<T> list;
    //对象
    private Object object;

    /**
     * 返回对象
     *
     * @param object 对象
     */
    public RestResult(Integer code, String message, Object object) {
        this.code = code;
        this.message = message;
        this.object = object;
    }

    /**
     * 返回集合
     *
     * @param list 集合
     */
    public RestResult(Integer code, String message, List<T> list) {
        this.code = code;
        this.message = message;
        this.list = list;
    }

    /**
     * 无返回值
     */
    public RestResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * @param list 集合
     */
    public static <T> RestResult ok(String msg, List<T> list) {
        return new RestResult(0, msg, list);
    }

    /**
     * @param o 对象
     */
    public static <T> RestResult ok(String msg, Object o) {
        return new RestResult(0, msg, o);
    }

    public static <T> RestResult ok(String msg) {
        return new RestResult(0, msg);
    }

    /**
     * @param msg 错误信息
     */
    public static <T> RestResult error(String msg) {
        return new RestResult(1, msg);
    }

    /**
     * 多错误代码无返回值有返回信息
     *
     * @param msg 错误信息
     */
    public static <T> RestResult error(Integer code, String msg) {
        return new RestResult(code, msg);
    }

}
